package com.cskaoyan.service;

import com.cskaoyan.bean.MallAdmin;
import com.cskaoyan.bean.MallAdminExample;
import com.cskaoyan.bean.data.BaseData;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.mapper.MallAdminMapper;
import com.cskaoyan.util.MyPageHelper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService{
    @Autowired
    MallAdminMapper adminMapper;

    @Override
    public BaseData<MallAdmin> query(BaseParam baseParam) {
        //PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
        MyPageHelper.startPage(baseParam);

        MallAdminExample example = new MallAdminExample();
        example.setOrderByClause(baseParam.getSort() + " " + baseParam.getOrder());
        List<MallAdmin> mallAdmins = adminMapper.selectByExample(example);

        long total = adminMapper.countByExample(example);

        return BaseData.ok(mallAdmins,total);
    }
}
